<?php
namespace Home\Controller;

class CategoryController extends BaseController {
    function index(){
		//获取类别信息
		
		$db = M('category');
		$re = $db->where(array('url'=>I('id')))->find();
		if(!$re){
			$this->_empty();
			exit;
		}else{
			$re['title'] = $re['title'] ? $re['title'] : $re['name'];
			$this->content = $re;
		}
		//单页
		if($re['type'] == 'page'){
			//获取评论
//			$db = M('book');
//			$this->bcount = $db->where(array('cid'=>$re['id'],'type'=>'page'))->count();
//			$this->book = $db->where(array('cid'=>$re['id'],'type'=>'page'))->select();
                        $db = M('category');
			$this->content = $db->where(array('url'=>I('id')))->find();
			$this->display('page');
			exit;
		}
		//列表
		
		$db = M('content');
		$shownum = F('ArticleShowNum');
		$page = isset($_GET['p']) ? $_GET['p'] : 1;
		$count         = $db->where(array('catid'=>$re['id']))->count();
		$Page          = new \Think\Page($count,$shownum);
		$purl = F('URL');
		$purl = str_replace('{url}',$re['url'],$purl['purl']);
		$purl = str_replace('{page}',urlencode('[PAGE]'),$purl);

		$Page->url     = $purl;
		$this->fenye    = $Page->show();
		$this->category    = $db->where(array('catid'=>$re['id']))->order('ord desc, id desc')->page($page.','.$shownum)->select();
                $this->display($re['type']);
    }
}